package com.automannn.seataSamples.stock.service.impl;

import com.automannn.seataSamples.api.dto.CommodityDTO;
import com.automannn.seataSamples.api.response.ObjectResponse;
import com.automannn.seataSamples.api.response.ResponseStatusEnum;
import com.automannn.seataSamples.stock.entity.StockPO;
import com.automannn.seataSamples.stock.mapper.StockMapper;
import com.automannn.seataSamples.stock.service.IStockService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author automannn
 * @Date 2022/3/24
 */
@Service
public class IStockServiceImpl extends ServiceImpl<StockMapper, StockPO>  implements IStockService {

    @Override
    public ObjectResponse decreaseStock(CommodityDTO commodityDTO) {
       int result= baseMapper.decreaseStock(commodityDTO.getCommodityCode(), commodityDTO.getCount());
       ObjectResponse response = new ObjectResponse();
       if(result>0){
           response.setStatus(ResponseStatusEnum.SUCCESS.getCode());
           response.setMessage(ResponseStatusEnum.SUCCESS.getMessage());
           return response;
       }
       response.setStatus(ResponseStatusEnum.FAIL.getCode());
       response.setMessage(ResponseStatusEnum.FAIL.getMessage());
        return response;
    }
}
